package ariman.pact.consumer.basepact;

import ariman.pact.consumer.Information;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class BasePactProviderService {

    private String backendURL = "http://localhost:8080/mytestProvider";

    public String getBackendURL() {
        return this.backendURL;
    }

    public void setBackendURL(String URLBase) {
        this.backendURL = URLBase+"/mytestProvider";
    }
   /* public void setBackendURL(String URLBase, String name) {
        this.backendURL = URLBase+"/information?name="+name;
    }*/

    public BaseDto getBaseDto() {
        RestTemplate restTemplate = new RestTemplate();
        //restTemplate.getForObject(getBackendURL(), BaseDto.class);
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        String params = "{\"aa\": \"testaa\",\"bb\":\"testbb\",\"number\":666}";
        HttpEntity formString = new HttpEntity(params,headers);
        BaseDto baseDto =  restTemplate.postForObject(getBackendURL(),formString,BaseDto.class);
        return baseDto;
    }


}
